layui.use(['layer', 'echarts', 'element', 'count'], function() {
    var $ = layui.jquery,
        layer = layui.layer,
        element = layui.element,
        count = layui.count,
        echarts = layui.echarts;

    //容器初始化
    var column1 = echarts.init(document.getElementById('column1'),null, {
        width: 600,
        height: 420
    });

    //图表样式定义
    option = {
        title: {
            text: '检测完成情况',
            subtext: 'Detected Conditions',
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
        },
        series: [
            {
                type: 'pie',
                radius: '50%',
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    //获取后端数据
    $.ajax({
        type: "get",
        url: "/homepage/selectalltask",
        contentType: "\"application/json;charset=utf-8\"",
        success: function (data) {
            console.log("=====data: =======")
            console.log(data);
            for (var i = 0, j=0, k=0; i < data.list.length; i++) {
                if(data.list[i].status === 1){
                    j++;
                }else{
                    k++;
                }
            }


            count.up("value3", {
                time: 4000,
                bit: 2,
                num: j,
                regulator: 50
            })
            count.up("value4", {
                time: 4000,
                bit: 2,
                num: k,
                regulator: 50
            })
            count.up("value5", {
                time: 4000,
                bit: 2,
                num: 3,
                regulator: 50
            })

            //图表赋值
            column1.setOption({

                series: [{
                    // 根据名字对应到相应的系列
                    data: [
                        {value:j, name:'已检测'},
                        {value:k, name:'待检测'}
                    ],
                    color:['#fcab95', '#87CEEB'],
                }]
            });
        }

    });

    column1.setOption(option);

    window.onresize = function() {
        column1.resize();
    }
    
})
